package com.gpslw.mvc.listener;

import com.gpslw.mvc.event.UserSaveEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
public class UserSaveListener implements ApplicationListener<UserSaveEvent> {


    @Override
    public void onApplicationEvent(UserSaveEvent event) {
        System.out.println("this is UserSaveEvent");
    }

    @TransactionalEventListener(value = {}, phase = TransactionPhase.BEFORE_COMMIT)
    public void onBeforeTransactionCommit(UserSaveEvent userSaveEvent){
        System.out.println("before commit");
    }

    @TransactionalEventListener(value = {}, phase = TransactionPhase.AFTER_COMMIT)
    public void onAfterTransactionCommit(UserSaveEvent userSaveEvent){
        System.out.println("after commit");
    }
}
